package com.p6spy.enginex;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.dbcp.BasicDataSource;
import com.p6spy.enginex.spy.Setting;

public class NightDbcpDataSource extends BasicDataSource {
	public Connection getConnection() throws SQLException {
		Connection conn = super.getConnection();
		return proxyConnection(conn);
	}

	public Connection getConnection(String username, String password)
			throws SQLException {
		Connection conn = super.getConnection(username, password);
		return proxyConnection(conn);
	}

	private Connection proxyConnection(Connection conn) throws SQLException {
		if (Setting.isCheckConnLeaks()) {
			ConnLeaksCheckUtils.addConn2Thread(conn);
		}
		return conn;
	}
}
